package com.liu.communitysystemend.module.license.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.liu.communitysystemend.module.license.domain.License;
import com.liu.communitysystemend.module.license.domain.LicenseDto;
import com.liu.communitysystemend.module.license.domain.QLicenseDto;
import com.liu.communitysystemend.module.license.service.LicenseService;
import com.liu.communitysystemend.utils.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author liu
 * @create 2023-03-17 20:22
 */
@RestController
@RequestMapping("/api/license")
public class LicenseController {
    @Autowired
    private LicenseService licenseService;

    @ApiOperation("更新车牌信息")
    @GetMapping("/get/{id}")
    public Result<License> getComplaints(@PathVariable("id")String id){
        return Result.success(licenseService.getVisitorById(id));
    }

    @ApiOperation("更新车牌信息")
    @PostMapping("modify")
    public Result<License> save(@RequestBody License license) {
        return Result.success(licenseService.update(license));
    }

//    @ApiOperation("添加车牌信息")
//    @PostMapping("add")
//    public Result<License> add(@RequestBody License license){
//        return Result.success(licenseService.add(license));
//    }

    @ApiOperation("查询车牌列表(分页)")
    @PostMapping("page")
    public Result<Page<LicenseDto>> getPage(@RequestBody License license) {
        return Result.success(licenseService.getPage(license));
    }

    @GetMapping("delete/{id}")
    @ApiOperation("删除车牌")
    public Result deleteById(@PathVariable("id") String id) {
        return licenseService.deleteById(id) > 0 ? Result.success() : Result.failed();
    }

    @ApiOperation("来访test")
    @GetMapping("/test")
    public Result test(){
        return Result.success(licenseService.test());
    }

    @ApiOperation("添加车牌信息")
    @PostMapping("add")
    public Result<License> addByCertNo(@RequestBody QLicenseDto qLicenseDto){
        return Result.success(licenseService.addByCertNo(qLicenseDto));
    }

}


